package com.zut.dao.impl;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

import com.zut.dao.UserDao;
import com.zut.entity.User;
import com.zut.utils.JDBCutil;

public class UserDaoImpl implements UserDao{

	@Override
	public User getUser(String name, String pwd) {
		
		Connection con=null;
		String url="jdbc:mysql://localhost:3306/apartment";
		String user="root";
		String pwd1="123456";
		String sql="SELECT * from user WHERE u_name=? and `u_pase`=?";
		PreparedStatement ps = JDBCutil.getPS(con, url, user, pwd1, sql);
		//设置参数
		try {
			ps.setString(1, name);
			ps.setString(2, pwd);
			//执行
			ResultSet rs=ps.executeQuery();
			User uu=new User();
			while(rs.next()){
				uu.setU_id(rs.getInt(1));
				uu.setU_name(rs.getString(2));
				uu.setU_pase(rs.getString(3));
				uu.setU_realname(rs.getString(4));
				uu.setU_sex(rs.getString(5));
				uu.getRole().setRo_name(rs.getString(6));
				uu.setU_create_time(rs.getString(7));
				uu.setU_state(rs.getInt(8));
			}
			
			return uu;  //一个方法遇到return 方法就结束了，不会再向下运行了
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return null;
	}

}
